package com.zxy.controller;

import com.zxy.dao.UserMapper;
import com.zxy.entity.User;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
@RequestMapping("user")
public class UserController {

    @Resource
    private UserMapper userMapper;
    /**
     * 跳转前端页面
     * @return
     */
    @RequestMapping("userList")
    public String toString() {
        return "user/userList";
    }

    /**
     * 获取UserList数据
     * @return
     */
    @RequestMapping("getData")
    @ResponseBody
    public Map<String, Object> getData() {
        List<User> userList = userMapper.getAllUser();

        // 组装layui table需要的数据格式
        /*  {
            "code": 0,
                "msg": "",
                "count": 1000,
                "data": [{}, {}]
        }*/
        Map<String, Object> map = new HashMap<>();
        map.put("code", 0);
        map.put("msg", "");
        map.put("count", userList.size());
        map.put("data", userList);
        return map;
    }
}
